# !/usr/bin/env python
# encoding: utf-8


"""
  @author: gaogao
  @file: read_ini_2_dict.py
  @time: 2022/4/19 15:36
  @desc:
"""

import configparser

ini_path = r"static/smu_setting.ini"
refrence_path = r"static/refrence_data.ini"
# refrence_path = r"D:\PyCharmProject\HS_ATS_VS\static\refrence_data.ini"
# refrence_path = r"C:\Users\Jingw\PycharmProjects\HS_ATS_VS\static\refrence_data.ini"
remember_path = r"static/remember_value.ini"


# ini_path = r"..\static\smu_setting.ini"


def read_ini_info_2_dict(ini_path=ini_path, section='pair_smu_instrument'):
    config = configparser.ConfigParser()
    config.read(ini_path, encoding='utf-8-sig')
    value_list = config.items(section)
    smu_inst_map = {}
    for value in value_list:
        smu_inst_map[value[0]] = value[1]
    if smu_inst_map:
        return smu_inst_map


def get_option_value(ini_path=remember_path, section='remember_value', option="loss_gc"):
    config = configparser.ConfigParser()
    config.read(ini_path, encoding='utf-8-sig')
    value = config.get(section, option)
    return value


def get_refrence_data(ini_path=refrence_path, section="loss_sys"):
    config = configparser.ConfigParser()
    config.read(ini_path, encoding='utf-8-sig')
    values = config.items(section)
    xy_data_tuple = (eval(values[0][1]), eval(values[1][1]))
    return xy_data_tuple


def get_pd_loss_sys(ini_path=refrence_path, section="pd_loss_sys"):
    config = configparser.ConfigParser()
    config.read(ini_path, encoding='utf-8-sig')
    values = config.items(section)
    xy_data_tuple = (eval(values[0][1]), eval(values[1][1]))
    return xy_data_tuple


# refrence_path = r"C:\Users\Jingw\PycharmProjects\HS_ATS_VS\static\refrence_data.ini"


def get_loss_data(ini_path=refrence_path, section="loss_gc_data"):
    config = configparser.ConfigParser()
    config.read(ini_path, encoding='utf-8-sig')
    values = config.items(section)
    loss_gc_tuple = (eval(values[0][1]), eval(values[1][1]))
    return loss_gc_tuple

# print(read_ini_info_2_dict(ini_path))
# print(get_option_value(r"D:\PyCharmProject\HC_ATS_VS\static\remember_value.ini"))
# value = get_refrence_data(r"D:\PyCharmProject\HC_ATS_VS\static\refrence_data.ini")
# print(value)
# print(get_loss_data(section="1_1_loss_gc_data"))
# print(get_pd_loss_sys())
